﻿using System;
using System.Windows.Forms;

namespace SPDevExplorer
{
    public partial class SiteExplorer
    {
        #region Delegates

        public delegate void LogEventDelegate(int severity, string text);

        #endregion

        public LogEventDelegate OnEvent;

        public void LogEvent(int severity, string text)
        {
            if (severity == 1)
                MessageBox.Show(text, "Error");

            if (OnEvent != null) OnEvent(severity, text);
        }

        public void LogEvent(Exception ex)
        {
            LogEvent(ex, true);
        }

        public void LogEvent(Exception ex, bool showMessage)
        {
            MessageBox.Show(ex.Message, "Error");

            if (OnEvent != null) OnEvent(1, ex.ToString());
        }

        //SvdO: Also want to be able to show a message AND the exception text
        public void LogEvent(string message, Exception ex)
        {
            string error = message + Environment.NewLine + Environment.NewLine + ex.Message;
            MessageBox.Show(error, "Error");

            if (OnEvent != null) OnEvent(1, message + Environment.NewLine + ex.ToString());
        }
    }
}